package com.demo.modalframe3.listener;

import com.demo.modalframe3.utils.AppendTextFrame;

import javax.swing.*;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;

public class FrameFocusListener extends FocusAdapter {

    @Override
    public void focusGained(FocusEvent e) {
        JFrame frame = (JFrame)e.getSource();
        if (frame instanceof AppendTextFrame) {
            ((AppendTextFrame)frame).appendText2TextPane(e.paramString());
        }
        super.focusGained(e);
    }

    @Override
    public void focusLost(FocusEvent e) {
        JFrame frame = (JFrame)e.getSource();
        if (frame instanceof AppendTextFrame) {
            ((AppendTextFrame)frame).appendText2TextPane(e.paramString());
        }
        super.focusLost(e);
    }
}
